import axios from "axios";
import {serialize} from "../utils/utils"

//默认超时时间
axios.defaults.timeout = 30000;

//http request拦截
axios.interceptors.request.use(
  config => {
    //headers中配置serialize为true开启序列化
    if (config.method === "post" && meta.isSerialize === true) {
      config.data = serialize(config.data);
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
//http response 拦截
axios.interceptors.response.use(
  res => {
    return res;
  },
  error => {
    return Promise.reject(new Error(error));
  }
);

export default axios;
